<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"sophimp.gitee.io","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="使用raw socket 实现 IPv6 的 tcp 通信, 验证可否使用raw socket 直接使用 volte 的ipv6呢？">
<meta property="og:type" content="article">
<meta property="og:title" content="Android raw socket in ipv6">
<meta property="og:url" content="http://sophimp.gitee.io/2020/07/29/android/android-raw-socket-ipv6/index.html">
<meta property="og:site_name" content="Sophimp&#39;s Space">
<meta property="og:description" content="使用raw socket 实现 IPv6 的 tcp 通信, 验证可否使用raw socket 直接使用 volte 的ipv6呢？">
<meta property="article:published_time" content="2020-07-29T05:42:43.000Z">
<meta property="article:modified_time" content="2021-03-15T03:49:47.918Z">
<meta property="article:author" content="Sophimp">
<meta property="article:tag" content="TCP">
<meta property="article:tag" content="Raw Socket">
<meta property="article:tag" content="IPv6">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://sophimp.gitee.io/2020/07/29/android/android-raw-socket-ipv6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-Hans'
  };
</script>

  <title>Android raw socket in ipv6 | Sophimp's Space</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

	
	<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
	

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Sophimp's Space</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">coding & thinking</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/sophimp" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="http://sophimp.gitee.io/2020/07/29/android/android-raw-socket-ipv6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Sophimp">
      <meta itemprop="description" content="A dream begin">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sophimp's Space">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Android raw socket in ipv6
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2020-07-29 13:42:43" itemprop="dateCreated datePublished" datetime="2020-07-29T13:42:43+08:00">2020-07-29</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-03-15 11:49:47" itemprop="dateModified" datetime="2021-03-15T11:49:47+08:00">2021-03-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="Views" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">Views: </span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
            <div class="post-description">使用raw socket 实现 IPv6 的 tcp 通信, 验证可否使用raw socket 直接使用 volte 的ipv6呢？</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><p>在使用LTE-4G的IPv6地址时，移动运营商的IPv6 不可被ping， 而每台手机开始volte的情况下， 会有两个IPv6 地址。<br>因此探究一下 raw socket 在 IPv6 上的 TCP 通信，是否可以使用 VoLTE的IPv6 呢？ 是否可控TCP SYN包长呢？ </p>
<h2 id="IPv6-协议"><a href="#IPv6-协议" class="headerlink" title="IPv6 协议"></a>IPv6 协议</h2><p>找到一个 <a href="http://www.pdbuchan.com/rawsock/tcp6_ll.c" target="_blank" rel="noopener">发送IPv6</a> 示例代码,<br>直接将此程序拿过来放到Android JNI 是可以直接编译成功的。但是出现了此问题</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">socket() failed to get socket descriptor for using ioctl()</span><br><span class="line">send raw tcp failed</span><br><span class="line"></span><br><span class="line">type&#x3D;1400 audit(0.0:806): avc: denied &#123; create &#125; for scontext&#x3D;u:r:untrusted_app_25:s0:c512,c768 tcontext&#x3D;u:r:untrusted_app_25:s0:c512,c768 </span><br><span class="line">tclass&#x3D;packet_socket permissive&#x3D;1</span><br></pre></td></tr></table></figure>

<p>这应该就是raw socket 所需 root权限的日志。 </p>
<p>如何获取root权限？ </p>
<ol>
<li><p>使用 magisk 的root, 如何去在app时申请root?<br> 有magisk 版本可以主动将app提权<br> 而现在使用的版本， 是自动检测， 有时候就会出现怎么着都不弹窗的提示, 且就算有 root权限， 也可能不能调用api, 这是SEAndroid 的机制<br> 所以希望还是放在SEAndroid 上</p>
</li>
<li><p>改 selinux 的 te文件, 只有定制ROM吗?<br> 修改了 untrustedted_app.te 文件，rom 编译不过去了, 看来简单的添加te 并不行。 </p>
</li>
<li><p>关闭selinux是否可行? </p>
</li>
</ol>
<p>方法一:</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 此方法重启后失效</span></span><br><span class="line">adb shell setenforce 0  <span class="comment"># 设置成permissive 模式</span></span><br><span class="line">adb shell setenforce 1  <span class="comment"># 设置成enforce 模式</span></span><br><span class="line">adb shell getenforce	<span class="comment"># 查看当前权限状态</span></span><br></pre></td></tr></table></figure>
<pre><code>这种方法对于raw socket并不起作用, 日志已经表示了permissive=1</code></pre><p>方法二:<br>    重新编译内核, 去掉 CONFIG_SECURITY_SELINUX=y</p>
<h2 id="root权限的获取"><a href="#root权限的获取" class="headerlink" title="root权限的获取"></a>root权限的获取</h2><p><a href="https://blog.csdn.net/su749520/article/details/80284543" target="_blank" rel="noopener">SE-Linux 问题解决-untrusted_app_25</a></p>
<p>修改 system/sepolicy/ 下的 untrusted_app_25.te， 编译都过不了,  编译内核时中断</p>
<pre><code>neverallow untrusted_app_25 base_typeattr_9 (packet_socket (ioctl read write create getattr setattr lock relabelfrom relabelto append map bind connect listen accept getopt setopt shutdown recvfrom sendto name_bind))

neverallow check failed at .../built_plat_sepolicy:9633 from system/sepolicy/private/app_neverallows.te:72

Falied to build policydb

到这里，只搜索，也看不懂内容了， 系统学习SEAndroid</code></pre><p>更多SEAndroid 解析， 有必要单独分析分析，单独写一篇或一个系列吧</p>
<p>解决了 raw socket 权限的问题, 接下来socket()打开失败，程序可以正常编译， 但是socket打不开是何原因？ </p>
<h2 id="raw-socket"><a href="#raw-socket" class="headerlink" title="raw socket"></a>raw socket</h2><p>socket 创建不成功</p>
<p>android 使用4G上网， 走的是基带吗？ 基带有网卡功能吗？</p>
<p>支不支持wifi下的socket通信? </p>
<p>ip电话是如何实现的?</p>
<p>ping通ping不通是因为有限制的NAT技术吗？ </p>
<pre><code>NAT是一方面， 没有active也是一方面, 禁ping也是有可能的</code></pre><p>打电话与发短信又走的是哪个通道? 能否利用这个通道? </p>
<pre><code>打电话与发短信使用的是Lte ipv6地址， 但都是经过ip协议来传输的
NAT搞的也是端口绑定，电话和短信应该是没有端口之说的, 使用的是号码。

使用NetworkInterface 可以查看网口， 可以使用

socket的bind方法可以选择网口。 </code></pre><p>Voip电话</p>
<pre><code>网络电话是如何实现的, 电话网系统(PSTN)</code></pre><p>volte 漏洞</p>
<pre><code>IP_VoLTE, IP_Data, 确实可以使用两个地址互相访问，现在漏洞已经修复了吗？
如何使用这两个ip, 在/proc/下并没有看到rmnet0, rmnet1, 但是可以在/proc/net/route 下看到rmnet0_data, rmnet1_ims

mokee8.1还不支持ipv6, 先移植一个9.0</code></pre><p>Android 如何指定网口发送数据?<br>    貌似从Java层面可以做到？ Socket 有bind接口， 绑定本地网卡ip 发送。</p>
<p>如何向sip服务器发送数据？ </p>
<pre><code>volte的ipv6 可以从 /proc/net/if_inet6 中查看
sip服务器地址可以从 /proc/net/ipv6_route 中查看

通过路由列表可以发送到任何ip

然而如何区分哪个是sip服务器呢？ 哪个又是volte的ipv6呢？ 人眼可以通过系统的显示来差异化区分，程序如何判断？ 

发送sip包如何继续通信? </code></pre><p>如何拿到signaling bearer</p>
<pre><code>先打一个电话或者发一条短信可行吗？ 
初步尝试，并不可行，

使用Data网口，可以同时ping通 目标的两个ip
使用VoLTE网口， 同时ping不通 目标的两个ip
但是TCP包只有同时为Data网口ip才有响应
移动作为目标两个ip都ping不通，

华为手机没有root权限查不到VoLTE网口IP</code></pre><p>如何使用这个signaling beaer通信</p>
<p>tcp抓包</p>
<h2 id="有用的链接"><a href="#有用的链接" class="headerlink" title="有用的链接"></a>有用的链接</h2><p><a href="https://zhuanlan.zhihu.com/p/26864594" target="_blank" rel="noopener">Android 使用指定网口收发数据</a><br><a href="https://www.it619.net/index.php?edition-view-318-1.html" target="_blank" rel="noopener">VoLTE Log 分析与主要SIP消息介绍</a><br><a href="http://drops.xmd5.com/static/drops/papers-10259.html" target="_blank" rel="noopener">破解并修复VoLTE: 利用隐藏的数据通道和错误的实现方式</a><br><a href="https://blog.apnic.net/2017/10/24/raw-sockets-ipv6/" target="_blank" rel="noopener">How to : Raw Socket in IPv6</a><br><a href="https://www.it619.com/forum.php?mod=viewthread&tid=429" target="_blank" rel="noopener">VoLTE注册流程详解</a><br><a href="http://www.suoniao.com/article/43496" target="_blank" rel="noopener">解决VoLTE IPv6 ping显示unreachable的问题</a><br><a href="https://juejin.im/post/6844904084168769549" target="_blank" rel="noopener">tcpdump抓包指南</a></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/TCP/" rel="tag"># TCP</a>
              <a href="/tags/Raw-Socket/" rel="tag"># Raw Socket</a>
              <a href="/tags/IPv6/" rel="tag"># IPv6</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/28/thought/thinking-about-programming/" rel="prev" title="编程杂谈">
      <i class="fa fa-chevron-left"></i> 编程杂谈
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/31/android/SEAndroid/android-selinux-1/" rel="next" title="Android SELinux 系列(一) 背景，作用，原理">
      Android SELinux 系列(一) 背景，作用，原理 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#背景"><span class="nav-number">1.</span> <span class="nav-text">背景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#IPv6-协议"><span class="nav-number">2.</span> <span class="nav-text">IPv6 协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#root权限的获取"><span class="nav-number">3.</span> <span class="nav-text">root权限的获取</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#raw-socket"><span class="nav-number">4.</span> <span class="nav-text">raw socket</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#有用的链接"><span class="nav-number">5.</span> <span class="nav-text">有用的链接</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Sophimp"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Sophimp</p>
  <div class="site-description" itemprop="description">A dream begin</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">86</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">89</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/sophimp" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sophimp" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:sophimp2020@126.com" title="E-Mail → mailto:sophimp2020@126.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sophimp</span>
</div>

<!--
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>
-->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
